import { EntityManager, MikroORM } from '@mikro-orm/mysql';
import { InjectEntityManager, InjectMikroORM } from '@mikro-orm/nestjs';
import { Body, Controller, Post,Req } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { knext } from 'knext';
import { JobProjectJobs } from '@databases/entities/JobProjectJobs';
import { JsonApiResponse } from '@utils/json.api.response';
import dayjs from 'dayjs';
import { result } from 'lodash';

@ApiTags('(管理员) 兼职-岗位')
@Controller('job')
export class JobController {
    constructor(
        @InjectMikroORM('zp')
        private readonly orm : MikroORM,
        @InjectEntityManager('zp')
        private readonly em : EntityManager
        
    ){}

    @Post('create_simple')
    async create_simple(@Req() request,@Body() body){
        let sql = knext(this)
        let id = await sql.fromORM(JobProjectJobs)
        .insert({
            ...body,
            created_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
            updated_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
        }).getOne()

        let job = await sql.fromORM(JobProjectJobs).select('*').where('id',id).getOne()

        return JsonApiResponse.object(job)
    }
}
